---
description: "Reference for Nitric's v0 Go library - Get a download url for a file from a bucket."
---

# Go - Bucket.File.DownloadUrl()

Create a download url for a file within a bucket.

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  bucket, err := nitric.NewBucket("bucket-name").With(nitric.BucketReading)
  if err != nil {
    return
  }

  uploadUrl, err := bucket.File("cat.png").DownloadUrl(context.TODO(), 3600)
  if err != nil {
    return
  }

  nitric.Run()
}
```

## Parameters

<Properties>
  <Property name="ctx" required type="context">
    The context of the call, used for tracing.
  </Property>
  <Property name="expiry" required type="int">
    Seconds until link expiry. Maximum of `604800` (7 days).
  </Property>
</Properties>

## Examples

### Create a readable link that is valid for the next 5 minutes

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  bucket, err := nitric.NewBucket("bucket-name").With(nitric.BucketReading)
  if err != nil {
    return
  }

  uploadUrl, err := bucket.File("cat.png").DownloadUrl(context.TODO(), 300)
  if err != nil {
    return
  }

  nitric.Run()
}
```

### Redirect response to an image URL

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/faas"
  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  api, err := nitric.NewApi("main")
  if err != nil {
    return
  }

  bucket, err := nitric.NewBucket("images").With(nitric.BucketReading)
  if err != nil {
    return
  }

  api.Get("/images/:id", func(ctx *faas.HttpContext, _ faas.HttpHandler) (*faas.HttpContext, error) {
    id := ctx.Request.PathParams()["id"]

    downloadUrl, err := bucket.File(id).DownloadUrl(context.TODO(), 600)
    if err != nil {
      return ctx, err
    }

    ctx.Response.Headers["Location"] = []string{downloadUrl}
    ctx.Response.Status = 303

    return ctx, nil
  })

  nitric.Run()
}
```
